<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head>
        <link rel="stylesheet" media="all" th:href="@{/admin/layui/css/layui.css}">
        <link rel="stylesheet" media="all" th:href="@{/admin/style/admin.css}">
    </head>
    <body>
        <div class="layui-form" lay-filter="layuiadmin-form" id="layuiadmin-form"
             style="padding: 20px 30px 0 0;">
            <div class="layui-form-item">
                <div class="layui-form-item">
                    <label class="layui-form-label">上级菜单</label>
                    <div class="layui-input-inline" id="parentMenu"></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-item">
                    <label class="layui-form-label">权限类型</label>
                    <div class="layui-input-inline left">
                        <input type="radio" name="type" value="1" title="目录" checked>
                        <input type="radio" name="type" value="2" title="按钮">
                    </div>
                    <label class="layui-form-label required">菜单排序</label>
                    <div class="layui-input-inline">
                        <input type="text" name="sort" lay-verify="required|sort" maxlength="4" class="layui-input"
                               placeholder="请输入菜单排序">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">菜单名称</label>
                <div class="layui-input-inline left">
                    <input type="text" name="name" lay-verify="required" class="layui-input" placeholder="请输入菜单名称">
                </div>
                <label class="layui-form-label">菜单图标</label>
                <div class="layui-input-inline">
                    <input type="text" name="icon" id="iconFonts" lay-filter="iconFonts" class="layui-input"
                           placeholder="请输入菜单图标">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">菜单URL</label>
                <div class="layui-input-inline left">
                    <input type="text" name="url" class="layui-input" placeholder="请输入菜单URL">
                </div>
                <label class="layui-form-label">权限标识</label>
                <div class="layui-input-inline">
                    <input type="text" name="perm" class="layui-input" placeholder="请输入权限标识">
                </div>
            </div>
            <div class="layui-form-item layui-hide">
                <button class="layui-btn" lay-submit lay-filter="LAY-submit" id="LAY-submit">提交</button>
            </div>
        </div>
    </body>
    <script th:src="@{/admin/layui/layui.js}"></script>
    <script>
        layui.config({
            base: '/admin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
            , xmSelect: 'xm-select' //
        }).use(['index', 'form', 'admin', 'xmSelect'], function () {
            var admin = layui.admin, xmSelect = layui.xmSelect, form = layui.form;
            // 下拉
            var initValue = ['[[${pid}]]'];
            //执行 Ajax 后重载
            admin.req({
                url: '../tree/-1'
                , done: function (res) {
                    xmSelect.render({
                        el: '#parentMenu',
                        name: 'pid',
                        tips: '顶级目录',
                        model: {label: {type: 'text'}},
                        radio: true,
                        clickClose: true,
                        tree: {
                            show: true,
                            strict: false,
                            expandedKeys: [-1],
                        },
                        height: 'auto',
                        data: res.data,
                        initValue: initValue,
                        prop: {
                            name: 'title',
                            value: 'id'
                        }
                    })
                }
            });

            form.verify({
                sort: [
                    /^(0|\+?[1-9][0-9]*)$/,
                    '请填写正整数'
                ]
            });
        })
    </script>
</html>